package dao

import (
	"app/internal/struct/store"
	"errors"
)

func (d *Dao) StoreBufferLicense(obj *store.License) error {

	return d.SetLicenseId(obj.Id, obj.LicenseCode)
}

func (d *Dao) SetLicenseId(id string, v interface{}) error {

	return d.licensechannel.StringSet(d.cf.License.Session+id, v)
}

func (d *Dao) GetLicenseId(id string) (string, error) {

	value, err := d.licensechannel.StringGet(d.cf.License.Session + id)
	if err != nil {
		return "", errors.New("id no found")
	}
	return value, nil
}

func (d *Dao) SetLicenseIdTimeout(id string, tm int64) error {

	return d.licensechannel.Expire(d.cf.License.Session+id, tm)
}

func (d *Dao) ClearCacheLicense() {

	d.licensechannel.ClearDB()

}

func (d *Dao) GetLicenseSize() int64 {

	return d.licensechannel.GetDBSize()
}
